package JUnit;

import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import protocol.Headers;
import Servlets.WhatsAppConstatnts;

public class Logout extends mainTest {

	@Before
	public void setUp() throws Exception {
		_url = "logout";
	}

	@Test
	public void test405() {
		String response1 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"POST /"
								+ _url
								+ ".jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		assertTrue(response1.contains("HTTP/1.1 " + Headers.STATUS_405));
	}

	@Test
	public void testLogoutunknownUser() {
		String response1 = this.runtest(new RunnableClient("localhost", 9969,
				"GET /" + _url + ".jsp HTTP/1.1\n\n$"));
		assertTrue(response1.contains(WhatsAppConstatnts.LOGOUT_MESSAGE));
	}

	@Test
	public void testSessionInvalidation() {
		String response1 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=userToAdd&Phone=123456\n$"));
		String cookie2 = this.getCookie(response1);
		this.runtest(new RunnableClient("localhost", 9969, "GET /" + _url
				+ ".jsp HTTP/1.1\nCookie: " + cookie2 + "\n\n$"));
		String response6 = this.runtest(new RunnableClient("localhost", 9969,
				"POST /list.jsp HTTP/1.1\nCookie: " + cookie2
						+ "\n\nList=Groups\n$"));
		assertTrue(response6.contains("HTTP/1.1 " + Headers.STATUS_403));

	}

}
